package com.jjkj.environmental.environmental.utils

import android.os.Looper
import android.util.Base64
import com.jjkj.environmental.environmental.exception.LongRunningException
import top.zibin.luban.Luban
import java.io.File
import java.net.URLEncoder

object FileHelp {
    fun converter(path: String): String {
        val file = File(path)
        if (Looper.getMainLooper().thread == Thread.currentThread()) {
            throw LongRunningException("不能在主线程进行耗时操作")
        }
        return URLEncoder.encode(
                Base64.encodeToString(
                        Luban.with(ActivityHelper.getStackTop())
                                .ignoreBy(200)
                                .load(file)
                                .get(path)
                                .readBytes()
                        , Base64.DEFAULT)
                , "utf-8")
    }
}